<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>axios 调用方法发送请求</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
</head>
<body>
    <button>get</button>
    <button>post</button>

    <script>
        //获取按钮
        const btns = document.querySelectorAll('button');

        //
        btns[0].addEventListener('click', async function(){
            // axios.get(url [, config]);
            let res = await axios.get('http://127.0.0.1:8090/server', {
                params: {
                    c: 300,
                    d: 400
                }
            });
            console.log(res);
        })

        //post 请求
        btns[1].addEventListener('click', async function(){
            // axios.post(url [, data] [, config])
            let res = await axios.post(
                'http://127.0.0.1:8090/server',   //url
                {g: 700, h: 800},                 //[data]
                {                                 //[config]
                    params: {
                        i: 900,
                        j: 1000
                    },
                    headers: {
                        k: 110,
                        l: 111
                    }
                }
            );

            console.log(res);
        })
    </script>
</body>
</html>